import store from '../../store/index'
import Vue from 'vue'

/***
 * 网络请求基类
 */
class ApiBase {

  static send(url,param) {
     if(param===null){
       param = {}
     }
    return  Vue.prototype.$http.post(url,{requestMsg: JSON.stringify(this.createRequestMsg(param))})

   }
  static send(url,param,time) {
     if(param===null){
       param = {}
     }
    return  Vue.prototype.$http.post(url,{requestMsg: JSON.stringify(this.createRequestMsg(param))},time)

   }

   //构造请求参数
   static createRequestMsg(param){
     let userInfo = store.getters.userInfo;
     let browerFinger = store.getters.browerFinger;
     let msg = {
       common: {
         userId: userInfo === null ? "" : userInfo.id,
         accessToken: userInfo === null ? "" : userInfo.userToken,
         browerFinger: browerFinger === null ? "" : browerFinger,
       },
       msgbody: param
     } ;
     return msg;
   }
}

export default ApiBase

